#ifndef VCCOLOR_H_
#define VCCOLOR_H_

#include <cv.h>

#define BGR_CODE 0
#define RGB_CODE 1
#define HSV_CODE 2
#define HLS_CODE 3
#define YUV_CODE 4


/**
 * \brief Color class used for Color Filtering
 * 
 * This class defines the colors to be used on the Vission Classifier application.
 * The colors are defined using the mean value and the standard deviation of the pixels of 
 * an image, in any of the following colorcodes:
 * <lu>
 * <li> RGB
 * <li> HSV
 * <li> HLS
 * </lu>
 * Using those values is then possible to calculate a low and a high umbral, which are 
 * used for the classification.
 */
class nxColor
{
	private:
	
		/**
		 * \brief Name of the color., int colorCode
		 */
		char nameC[30];
		

		/**
		 * \brief mean Value in RGB code.
		 */
		CvScalar meanValue_RGB;
		
		/**
		 * \brief standard deviation Value in RGB code.
		 */
		CvScalar stdDev_RGB;
		
		/**
		 * \brief mean Value in HSV code.
		 */
		CvScalar meanValue_HSV;
		
		/**
		 * \brief standard deviation Value in HSV code.
		 */
		CvScalar stdDev_HSV;
		
		/**
		 * \brief mean Value in HLS code.
		 */
		CvScalar meanValue_HLS;
		
		/**
		 * \brief standard deviation Value in HLS code.
		 */
		CvScalar stdDev_HLS;
		
		/**
		 * \brief mean Value in HLS code.
		 */
		CvScalar meanValue_YUV;

		/**
		 * \brief standard deviation Value in HLS code.
		 */
		CvScalar stdDev_YUV;


		/**
		 * \brief Low Umbral used for the classification.
		 */
		CvScalar lowUmbral_RGB;
		
		/**
		 * \brief High Umbral used for the classification.
		 */
		CvScalar hiUmbral_RGB;
		 
		/**
		 * \brief Low Umbral used for the classification.
		 */
		CvScalar lowUmbral_HLS;
		
		/**
		 * \brief High Umbral used for the classification.
		 */
		CvScalar hiUmbral_HLS;
		
		/**
		 * \brief Low Umbral used for the classification.
		 */
		CvScalar lowUmbral_HSV;
		
		/**
		 * \brief High Umbral used for the classification.
		 */
		CvScalar hiUmbral_HSV;
		
		/**
		 * \brief Low Umbral used for the classification.
		 */
		CvScalar lowUmbral_YUV;

		/**
		 * \brief High Umbral used for the classification.
		 */
		CvScalar hiUmbral_YUV;

	public:
	
		/**
		 * \brief Constructor of the class.
		 * 
		 * The constructor calculates the mean and std dev. values in the three colorcodes specified.
		 * That gives a better performance when working with diferent colorcodes, because it is possible
		 * to use the same instance of color no matter the colorcode being used.
		 * 
		 * \param name The name of the color.
		 * \param cvImg the image from which the mean and std dev. values will be calculated. the format of 
		 * the image is IplImage (see OpenCV).
		 * \param colorCode the colorcode used on the cvImg.
		 */
		nxColor(char* name,IplImage* cvImg, int colorCode);
		
		nxColor(char* name, CvScalar mean[], CvScalar stdDev[]);
		
		/**
		 * \brief destructor of the class
		 */
		~nxColor();
		
		/**
		 * \brief returns the mean value in the given colorcode, passed as parameter.
		 * 
		 * The mean Value will be returned in the form of a CvScalar (see OpenCV). 
		 * 
		 * \param colorCode The colorCode desired for the mean Value returned.
		 * \return mean value in CvScalar format.
		 */
		CvScalar getMeanValue(int colorCode);
		
		int getMeanValueInt(int colorCode);
		
		/**
		 * \brief returns the standard deviation value in the given colorcode, passed as parameter.
		 * 
		 * The standard deviation value will be returned in the form of a CvScalar (see OpenCV). 
		 * 
		 * \param colorCode The colorCode desired for the standard deviation value returned.
		 * \return standard deviation  value in CvScalar format.
		 */
		CvScalar getStdDev(int colorCode);
		
		/**
		 * \brief Returns the low umbral defined for the instance of the color.
		 * 
		 * The low umbral is used to define the lower limit from which a pixel can be considered as the 
		 * instanced color. This umbral is calculated with the given coeficients passed as parameters, and
		 * in the given colorcode, also passed as parameter.
		 * The calculation of the low umbral is presented as follows:
		 * 
		 *  lowUmbral[i] = meanVal[i] - coef[i] * stdDev[i]
		 *
		 * \param colorCode the colorcode desired for the lowUmbral
		 * \param coef the coeficients to establish the relation between mean and std dev. values.
		 * \return lowUmbral in the form of CvScalar (see OpenCV)
		 */
		CvScalar getLowUmbral(int colorCode);
		
		
		/**
		 * \brief Returns the high umbral defined for the instance of the color.
		 * 
		 * The high umbral is used to define the higher limit from which a pixel can be considered as the 
		 * instanced color. This umbral is calculated with the given coeficients passed as parameters, and
		 * in the given colorcode, also passed as parameter.
		 *
		 * highUmbral[i] = meanVal[i] + coef[i] * stdDev[i]
		 * 
		 * \param colorCode the colorcode desired for the highUmbral
		 * \param coef the coeficients to establish the relation between mean and std dev. values.
		 * \return highUmbral in the form of CvScalar (see OpenCV)
		 */
		CvScalar getHighUmbral(int colorCode);
		
		/**
		 * \brief returns the name of the instance of color
		 * 
		 * \return the name of the instanced color.
		 */
		inline char* getName(){return this->nameC;}
		
		void setHighUmbral(CvScalar hiUmbral, int colorCode);
		void setLowUmbral(CvScalar lowUmbral, int colorCode);
		void resetUmbrals();
		static int scalar2int(CvScalar color);
		

};
#endif /*COLORCLASS_H_*/
